package com.wuh.controller;

import com.github.pagehelper.PageInfo;
import com.wuh.model.ClassInfor;
import com.wuh.service.ClassInforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wuh.model.Link;
import com.wuh.model.SysActive;
import com.wuh.service.LinkService;
import com.wuh.service.SysActiveService;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;


@Controller
public class IndexController {

	@Autowired
    private LinkService linkService;
	@Autowired
    private SysActiveService sysActiveService;
	@Autowired
    private ClassInforService classInforService;

    @RequestMapping("/")
    public String toIndex(){
            return "index";
    }

    @RequestMapping("/toMain")
    public String toMain(SysActive sysActive, Model model,HttpSession session){
    	//加载活动表信息 课程 老师
        ClassInfor classInfor = new ClassInfor();
        //加载最新公开课数据
        PageInfo<ClassInfor> newClassInfor = classInforService.queryClassAllByDate(classInfor);
//        System.err.println("加载的最新公开课newClassInfor：" + newClassInfor);
        session.setAttribute("newClassInfor", newClassInfor);
        List<SysActive> sysActives = sysActiveService.queryAll(sysActive);
        model.addAttribute("sysActives", sysActives);
    	return  "main";
    }


    @RequestMapping("/toFooter")
    public String toFooter(Link link,Model model) {
		List<Link> allLinks = linkService.getAllLinks(link);
		model.addAttribute("allLinks",allLinks);

		return "footer";
	}

    @RequestMapping("/toLogin")
    public String toLogin(){
        return  "loginreg/login";
    }

    @RequestMapping("/toUserIndex")
    public String toUserIndex(){
        return  "person/user_index";
    }
    @RequestMapping("/toUserInfo")
    public String toUserInfo(Model model){
        List<Integer> year =new ArrayList<>();
        for (int i=1960;i<=2020;i++){
            year.add(i);
        }
        List<String> month =new ArrayList<>();
        month.add("01");
        month.add("02");
        month.add("03");
        month.add("04");
        month.add("05");
        month.add("06");
        month.add("07");
        month.add("08");
        month.add("09");
        month.add("10");
        month.add("11");
        month.add("12");
        model.addAttribute("year", year);
        model.addAttribute("month", month);
        return  "person/user_info";
    }


    @RequestMapping("/toRegister")
    public String toRegister(){
        return  "loginreg/register";
    }



    @RequestMapping("/exitLogin")
    public  String exitLogin(HttpSession session){
    	session.removeAttribute("sess_user");
    	session.removeAttribute("loginMessage");
        return "index";
    }
}
